#include <QtGui>
#include <QtWidgets>
#include <QDir>
#include "mythread.h"
#include "reimage.h"
#include "rename.h"
#include <QDebug>

MyThread::MyThread(QObject *parent)
    :QThread(parent)
{
}

MyThread::~MyThread()
{
    
}

void MyThread::set_rename(QStringList form, QStringList to) {
    list        = form;
    list_save   = to;
}

void MyThread::set_image(int width, int height, int quality, Reimage::Type type) {
    save_width  = width;
    save_height = height;
    save_quality= quality;
    save_type   = type;
}

void MyThread::run()
{
    bool    status      = false;
    Reimage *reimage    = new Reimage();
    reimage->set_width(save_width);
    reimage->set_height(save_height);
    
    for(int i = 0; i < list.count(); ++i)
    {
        QString filename        = list.at(i);
        QString filename_save   = list_save.at(i);
        reimage->set_filename_save(filename_save);
        switch (save_type) {
        case Reimage::Type_Null:
            status = QFile::rename(filename, filename_save);
            break;
        default:            
            status = reimage->load(filename);
            if(status){
                reimage->run(save_type);
                status = reimage->save(save_quality);
            }
            break;
        }
        emit send_status(i, status);
    }
}
